//
//  TixianViewController.m
//  customer
//
//  Created by 往返网络 on 17/8/24.
//  Copyright © 2017年 com. All rights reserved.
//
#import "TixianViewController.h" //提现
#import "ZhifuPass1ViewController.h" //发送验证码
#import "ConfigTixianViewController.h" //提现确认界面
#import "PublicMethod.h"
#define return_tag 1000
#define next_tag 1001
#define tixian_tag 1002
#define cancel_tag 2003
#define forget_tag 2004
#define kDotSize CGSizeMake (10, 10) //密码点的大小
#define kDotCount 6  //密码个数
#define K_Field_Height 110.0/H_BASE*SCREEN_H  //每一个输入框的高度
#define min_h 80.0/H_BASE*SCREEN_H
#define begin_x 25.0/W_BASE*SCREEN_W
//定义提现下一步URL
#define URL_NEXTIXIAN [NSString stringWithFormat:@"%@/Appcustomernewer/Pay/payGetCashToSecond?type=get",BASE_URL]
//定义查询银行卡URL
#define URL_CHECKBANK [NSString stringWithFormat:@"%@/Appcustomernewer/Pay/payMyCard?type=get",BASE_URL]

@interface TixianViewController ()<UITextFieldDelegate>
@property (nonatomic,strong)AFHTTPSessionManager* manger;
@end

@implementation TixianViewController
{
    UITextField * banknumtf; //银行卡号
    UITextField * usernametf; //账户名
    UITextField * banknaemtf; //开户行
    UITextField * jinetf; //转账金额
    UILabel * yuelabel; //账户余额
    UITextField * textFieldmima; //密码输入TF
    UIView * zhifuview; //支付密码界面
    NSMutableArray * dotArray; //用于放密码黑点的数组
    UIView * mengbanview; //蒙板
    UIButton * nextbtn; //下一步
    UILabel * fuwulabel; //服务金额label
    NSString * pszhifustr; //支付密码
}
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self checkBank];
    [self createUI];
    
    // Do any additional setup after loading the view.
}

#pragma mark  --------- -- - - - - - - 查询当前银行卡－ － －－ － － － － － －
- (void)checkBank{
    
    //请求账号信息，余额等，赋值。。
    UIImageView * ima = [PublicMethod startAnimation];
    
    NSString * token = [[NSUserDefaults standardUserDefaults]objectForKey:USER_TOCKE];
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@",URL_CHECKBANK,token];
    
    NSLog(@"充值银行卡 url %@",url);
    
    [self.manger GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            
            if (code == 0) {
                // 停止动画
                [ima stopAnimating];
                //获得银行卡号，余额，银行名称，logo ID值
                NSDictionary * info = dict[@"info"];
                yuelabel.text = [NSString stringWithFormat:@"账户余额%@元",info[@"balance"]];
                
            }else{
                [ima stopAnimating];
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
            }
            
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        [ima stopAnimating];
        
    }];
}





- (void)nextTixian{
    
    UIImageView * ima = [PublicMethod startAnimation];
    
    NSString * token = [[NSUserDefaults standardUserDefaults]objectForKey:USER_TOCKE];
    
    NSString * url = [NSString stringWithFormat:@"%@&token=%@&money=%@&password=%@&accountNo=%@&accountName=%@&accountBankName=%@",URL_NEXTIXIAN,token,jinetf.text,pszhifustr,banknumtf.text,usernametf.text,banknaemtf.text];
    NSString * URL  = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"提现下一步 url %@",URL);

    [self.manger GET:URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (responseObject) {
            
            NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            NSInteger code = [dict[@"code"]integerValue];
            NSLog(@"dict %@",dict);
            if (code == 0) {
                // 停止动画
                [ima stopAnimating];
                //进入提现确认界面
                ConfigTixianViewController * configvc = [[ConfigTixianViewController alloc]init];
                configvc.jinestring = jinetf.text;
                configvc.banknumstring  = banknumtf.text;
                configvc.accountNo = banknumtf.text;
                configvc.accountName = usernametf.text;
                configvc.accountBankName = banknaemtf.text;
                NSLog(@"banknum %@,jine %@",banknumtf.text,jinetf.text);
                [self.navigationController pushViewController:configvc animated:YES];

                
            }else{
                [ima stopAnimating];
                ALERT(@"提示", dict[@"info"], self, @"确定", nil);
                
            }
            
        }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        ALERT(@"提示", @"网络请求失败", self, @"确定", nil);
        
        [ima stopAnimating];
        
    }];
}

- (void)createUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    float fontsize = 17;
    
    fontsize = SCREEN_H < 667 ? 15 : 19;
    
    if (SCREEN_H == 667) {
        
        fontsize = 17;
    }
    self.view.backgroundColor = COLORRGBA(239, 239, 239, 1);
    //设置表头
    UIView * titleview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 128.0/1334*SCREEN_H)];
    
    titleview.backgroundColor = COLORRGBA(7, 24, 57, 1);
    
    [self.view addSubview:titleview];
    
    //title
    UILabel * titlelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20.0, SCREEN_W, 90.0/H_BASE*SCREEN_H)];
    titlelab.text = @"提现";
    
    titlelab.textColor = [UIColor whiteColor];
    
    [self.view addSubview:titlelab];
    
    titlelab.textAlignment = NSTextAlignmentCenter;
    
    titlelab.font = [UIFont systemFontOfSize:fontsize];
    
    UILabel * leftlable  = [[UILabel alloc]initWithFrame:CGRectMake(0, 20+14.0/1334*SCREEN_H, 150.0/W_BASE*SCREEN_W, 60.0/1334.0*SCREEN_H)];
    leftlable.textAlignment = NSTextAlignmentCenter;
    NSString * endstr = @"\U0000e697";
    NSString * text = [NSString stringWithFormat:@"%@%@",endstr,@"返回"];
    leftlable.attributedText = [self changeLabelWithText2:text andStartplace:endstr andendplae:nil andfontsize:fontsize-2];
    leftlable.textColor = [UIColor whiteColor];
    [self.view addSubview:leftlable];
    
    UIButton * returnbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 150.0/W_BASE*SCREEN_W, 150.0/H_BASE*SCREEN_H)];
    [returnbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    returnbtn.tag = return_tag;
    [self.view addSubview:returnbtn];
    
    UIView * backview = [[UIView alloc]initWithFrame:CGRectMake(0, 127.0/H_BASE*SCREEN_H, SCREEN_W, SCREEN_H-127.0/H_BASE*SCREEN_H)];
    backview.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [self.view addSubview:backview];
    
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(titleview.frame)+20.0/H_BASE*SCREEN_H, SCREEN_W, min_h)];
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];
    
    UILabel * banktitle = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 0, 160.0/W_BASE*SCREEN_W, min_h)];
    banktitle.text = @"银行卡号";
    banktitle.textColor = COLORRGBA(102, 102, 102, 1);
    banktitle.textAlignment = NSTextAlignmentLeft;
    [view1 addSubview:banktitle];
    banktitle.font = [UIFont systemFontOfSize:fontsize-2];
    
    banknumtf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(banktitle.frame), 0, SCREEN_W - CGRectGetMaxX(banktitle.frame)-25.0/W_BASE*SCREEN_W, min_h)];
    banknumtf.textAlignment = NSTextAlignmentRight;
    banknumtf.placeholder = @"请输入银行卡号";
    banknumtf.keyboardType = UIKeyboardTypeNumberPad;
    banknumtf.delegate = self;
    banknumtf.clearButtonMode = UITextFieldViewModeWhileEditing;
    banknumtf.font = [UIFont systemFontOfSize:fontsize-4];
    [view1 addSubview:banknumtf];
    
    UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view1.frame)+20.0/H_BASE*SCREEN_H, SCREEN_W, min_h)];
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    
    UILabel * usertitle = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 0, 160.0/W_BASE*SCREEN_W, min_h)];
    usertitle.text = @"账户姓名";
    usertitle.textColor = COLORRGBA(102, 102, 102, 1);
    usertitle.textAlignment = NSTextAlignmentLeft;
    [view2 addSubview:usertitle];
    usertitle.font = [UIFont systemFontOfSize:fontsize-2];
    
    usernametf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(usertitle.frame), 0, SCREEN_W - CGRectGetMaxX(usertitle.frame)-25.0/W_BASE*SCREEN_W, min_h)];
    usernametf.textAlignment = NSTextAlignmentRight;
    usernametf.placeholder = @"请输入姓名";
    usernametf.delegate = self;
    usernametf.clearButtonMode = UITextFieldViewModeWhileEditing;
    usernametf.font = [UIFont systemFontOfSize:fontsize-4];
    [view2 addSubview:usernametf];
    
    UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view2.frame)+20.0/H_BASE*SCREEN_H, SCREEN_W, min_h)];
    view3.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view3];
    
    UILabel * banknametitle = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 0, 160.0/W_BASE*SCREEN_W, min_h)];
    banknametitle.text = @"开户行名称";
    banknametitle.textColor = COLORRGBA(102, 102, 102, 1);
    banknametitle.textAlignment = NSTextAlignmentLeft;
    [view3 addSubview:banknametitle];
    banknametitle.font = [UIFont systemFontOfSize:fontsize-2];
    
    banknaemtf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(usertitle.frame), 0, SCREEN_W - CGRectGetMaxX(usertitle.frame)-25.0/W_BASE*SCREEN_W, min_h)];
    banknaemtf.textAlignment = NSTextAlignmentRight;
    banknaemtf.placeholder = @"请输入开户行名称";
    banknaemtf.clearButtonMode = UITextFieldViewModeWhileEditing;
    banknaemtf.font = [UIFont systemFontOfSize:fontsize-4];
    banknaemtf.delegate = self;
    [view3 addSubview:banknaemtf];

    UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view3.frame)+20.0/H_BASE*SCREEN_H, SCREEN_W, 200.0/H_BASE*SCREEN_H)];
    view4.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view4];
    
    UILabel * zhuanjine = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, 0, 150.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    zhuanjine.text = @"提现金额";
    zhuanjine.textColor = COLORRGBA(102, 102, 102, 1);
    [view4 addSubview:zhuanjine];
    zhuanjine.font = [UIFont systemFontOfSize:fontsize-3];
    zhuanjine.textAlignment= NSTextAlignmentLeft;
    UILabel * iconmoney = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, CGRectGetMaxY(zhuanjine.frame), 80.0/W_BASE*SCREEN_W, 40.0/H_BASE*SCREEN_H)];
    iconmoney.textAlignment = NSTextAlignmentLeft;
    iconmoney.textColor = COLORRGBA(47, 165, 255, 1);
    iconmoney.text = @"￥";
    iconmoney.font = [UIFont systemFontOfSize:fontsize+8];
    [view4 addSubview:iconmoney];
    
    jinetf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(iconmoney.frame), CGRectGetMinY(iconmoney.frame), SCREEN_W - CGRectGetMaxX(iconmoney.frame), 40.0/H_BASE*SCREEN_H)];
    jinetf.font = [UIFont systemFontOfSize:fontsize];
    jinetf.delegate = self;
    jinetf.placeholder = @"请输入金额";
    jinetf.keyboardType = UIKeyboardTypeDecimalPad; //带小数点
    [view4 addSubview:jinetf];
    
    UIView * breakline = [[UIView alloc]initWithFrame:CGRectMake(begin_x, 140.0/H_BASE*SCREEN_H, SCREEN_W-50.0/W_BASE*SCREEN_W, 1)];
    breakline.backgroundColor = COLORRGBA(239, 239, 239, 1);
    [view4 addSubview:breakline];
    yuelabel = [[UILabel alloc]initWithFrame:CGRectMake(begin_x, CGRectGetMaxY(breakline.frame), 340.0/W_BASE*SCREEN_W, 60.0/H_BASE*SCREEN_H)];
    yuelabel.text = [NSString stringWithFormat:@"账户余额%@元",_balance];

    [view4 addSubview:yuelabel];
    yuelabel.font = [UIFont systemFontOfSize:fontsize-4];
    yuelabel.textColor = COLORRGBA(153, 153, 153, 1);

    UILabel * tixianlabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W - 175.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakline.frame), 150.0/W_BASE*SCREEN_W, 60.0/H_BASE*SCREEN_H)];
    tixianlabel.textColor = COLORRGBA(47, 165, 255, 1);
    tixianlabel.text = @"全部提现";
    tixianlabel.textAlignment  = NSTextAlignmentRight;
//    [view4 addSubview:tixianlabel];
    tixianlabel.font = [UIFont systemFontOfSize:fontsize -4];
    UIButton * tixianbtn = [[UIButton alloc]initWithFrame:tixianlabel.frame];
//    [view4 addSubview:tixianbtn];
    [tixianbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    tixianbtn.tag  = tixian_tag;
    
    nextbtn = [[UIButton alloc]initWithFrame:CGRectMake(begin_x, CGRectGetMaxY(view4.frame)+30.0/H_BASE*SCREEN_H, SCREEN_W - 50.0/W_BASE*SCREEN_W, min_h)];
    nextbtn.backgroundColor = COLORRGBA(59, 214, 117, 0.5);
    [self.view addSubview:nextbtn];
    [nextbtn setTitle:@"下一步" forState:UIControlStateNormal];
    [nextbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize-2];
    nextbtn.userInteractionEnabled = NO;
    nextbtn.layer.cornerRadius = 2;
    nextbtn.clipsToBounds = YES;
    [nextbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    nextbtn.tag = next_tag;
    
    //支付输入密码
    mengbanview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 397.0/H_BASE*SCREEN_H)];
    mengbanview.backgroundColor = COLORRGBA(153, 153, 153, 0.4);
    
    zhifuview = [[UIView alloc]initWithFrame:CGRectMake(0, 397.0/H_BASE*SCREEN_H, SCREEN_W, SCREEN_H-397.0/H_BASE*SCREEN_H)];
    zhifuview.backgroundColor = [UIColor whiteColor];
    //    [self.view addSubview:zhifuview];
    UIButton * cancelbtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 112.0/W_BASE*SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    //    cancelbtn.backgroundColor = [UIColor yellowColor];
    [zhifuview addSubview:cancelbtn];
    [cancelbtn setTitle:@"\U0000e69a" forState:UIControlStateNormal];
    cancelbtn.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize];
    cancelbtn.tag = cancel_tag;
    [cancelbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    [cancelbtn setTitleColor:COLORRGBA(159, 159, 159, 1) forState:UIControlStateNormal];
    UILabel * zhifulab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, 112.0/W_BASE*SCREEN_W)];
    zhifulab.text = @"请输入支付密码";
    [zhifuview addSubview:zhifulab];
    zhifulab.font = [UIFont systemFontOfSize:fontsize +1];
    zhifulab.textColor = [UIColor blackColor];
    zhifulab.textAlignment = NSTextAlignmentCenter;
    UIView * breakview = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(zhifulab.frame), SCREEN_W, 0.5)];
    breakview.backgroundColor = COLORRGBA(204, 204, 204, 1);
    [zhifuview addSubview:breakview];
    //    zhifuview.hidden = YES;
    
    fuwulabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(breakview.frame), SCREEN_W, 80.0/H_BASE*SCREEN_H)];
       [zhifuview addSubview:fuwulabel];
    fuwulabel.textAlignment = NSTextAlignmentCenter;
    fuwulabel.font = [UIFont systemFontOfSize:fontsize-5];
    textFieldmima = [[UITextField alloc] initWithFrame:CGRectMake(30.0/W_BASE*SCREEN_W, CGRectGetMaxY(breakview.frame)+80.0/H_BASE*SCREEN_H, SCREEN_W - 60.0/W_BASE*SCREEN_W, K_Field_Height)];
    textFieldmima.backgroundColor = [UIColor whiteColor];
    //输入的文字颜色为白色
    textFieldmima.textColor = [UIColor whiteColor];
    //输入框光标的颜色为白色
    textFieldmima.tintColor = [UIColor whiteColor];
    textFieldmima.delegate = self;
    textFieldmima.autocapitalizationType = UITextAutocapitalizationTypeNone;
    textFieldmima.keyboardType = UIKeyboardTypeNumberPad;
    textFieldmima.layer.borderColor = [COLORRGBA(204, 204, 204, 1)CGColor];
    textFieldmima.layer.borderWidth = 1;
    [textFieldmima addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [zhifuview addSubview:textFieldmima];
    [self initPwdTextField];//创建密码tf的分割线
    
    UIButton * forgetbtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_W - 137.0/W_BASE*SCREEN_W-26.0/W_BASE*SCREEN_W, CGRectGetMaxY(textFieldmima.frame), 137.0/W_BASE*SCREEN_W, 70.0/H_BASE*SCREEN_H)];
    //    forgetbtn.backgroundColor = [UIColor purpleColor];
    forgetbtn.titleLabel.textAlignment = NSTextAlignmentRight;
    forgetbtn.titleLabel.font = [UIFont systemFontOfSize:fontsize-3];
    [forgetbtn setTitle:@"忘记密码?" forState:UIControlStateNormal];
    [forgetbtn setTitleColor:COLORRGBA(47, 165, 255, 1) forState:UIControlStateNormal];
    [zhifuview addSubview:forgetbtn];
    forgetbtn.tag = forget_tag;
    [forgetbtn addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    

    
}
/**
 *  重置显示的点
 */
- (void)textFieldDidChange:(UITextField *)textField
{
    NSLog(@"%@", textField.text);
    if (textField == textFieldmima) {
        for (UIView *dotView in dotArray) {
            dotView.hidden = YES;
        }
        for (int i = 0; i < textField.text.length; i++) {
            ((UIView *)[dotArray objectAtIndex:i]).hidden = NO;
        }
        if (textField.text.length == kDotCount) {
            NSLog(@"输入完毕");
        }
        
    }
    
}


#pragma mark  - - -- - - - - - 将输入密码的tf分割成点 － － － － － － － － － － －
- (void)initPwdTextField
{
    //每个密码输入框的宽度
    CGFloat width = (SCREEN_W - 32) / kDotCount;
    //生成分割线
    for (int i = 0; i < kDotCount - 1; i++) {
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFieldmima.frame) + (i + 1) * width, CGRectGetMinY(textFieldmima.frame), 1, K_Field_Height)];
        lineView.backgroundColor = COLORRGBA(204, 204, 204, 1);
        [zhifuview addSubview:lineView];
    }
    dotArray = [[NSMutableArray alloc] init];
    //生成中间的点
    for (int i = 0; i < kDotCount; i++) {
        UIView *dotView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(textFieldmima.frame) + (width - kDotCount) / 2 + i * width, CGRectGetMinY(textFieldmima.frame) + (K_Field_Height - kDotSize.height) / 2, kDotSize.width, kDotSize.height)];
        dotView.backgroundColor = [UIColor blackColor];
        dotView.layer.cornerRadius = kDotSize.width / 2.0f;
        dotView.clipsToBounds = YES;
        dotView.hidden = YES; //先隐藏
        [zhifuview addSubview:dotView];
        //把创建的黑色点加入到数组中
        [dotArray addObject:dotView];
    }
}

#pragma mark  -  -  起始地＋发货人名（终止地＋收货人名）格式化 － － －-- - -  -
-(NSMutableAttributedString*)changeLabelWithText2:(NSString*)needText andStartplace:(NSString *)startplace andendplae:(NSString *)endplace andfontsize:(float)fontsize
{
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
    NSInteger startlength = startplace.length;
    //起始格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"iconfont" size:fontsize+2] range:NSMakeRange(0,startlength)];
    //    //尾部格式化
    [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontsize] range:NSMakeRange(startlength , needText.length  - startlength)];
    return attrString;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)clearUpPassword
{
    textFieldmima.text = @"";
    [self textFieldDidChange:textFieldmima];
}

#pragma mark - - - - - - - - - - Textfield Delegate  - -- - - - - - - -- - - - - -
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    //输入1位，下一步按钮变色
    NSString * textstring = [textField.text stringByReplacingCharactersInRange:range withString:string];
    pszhifustr = textstring;
    if (textField == jinetf) {
        if (textstring.length >= 1) {
            nextbtn.backgroundColor = COLORRGBA(59, 214, 117, 1);
            nextbtn.userInteractionEnabled = YES;
            [nextbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            //            zhifuview.hidden = NO;
        }
    }
    else if (textField == textFieldmima){ //输入密码
        if([string isEqualToString:@"\n"]) {
            //按回车关闭键盘
            [textField resignFirstResponder];
            return NO;
        } else if(string.length == 0) {
            //判断是不是删除键
            return YES;
        }
        else if(textstring.length >= kDotCount) {
            //输入的字符个数大于6，则无法继续输入，返回NO表示禁止输入
            NSLog(@"输入的字符个数大于6，忽略输入");
            [self.view endEditing:YES];
            //判断密码是否正确，正确则提示校验成功
            [zhifuview removeFromSuperview];
            [mengbanview removeFromSuperview];
            for (int i = 0; i < textField.text.length; i++) {
                ((UIView *)[dotArray objectAtIndex:i]).hidden = YES;
            }
           
            [self nextTixian];
            [self clearUpPassword];// 清除密码
            return NO;
        } else {
            return YES;
        }
        
    }else if (textField == banknumtf){
        //银行卡号4位一限定，限5组。。。20位
        NSString *text = [banknumtf text];
        NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"];
        string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
        if ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) {
            return NO;
        }
        text = [text stringByReplacingCharactersInRange:range withString:string];
        text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
        NSString *newString = @"";
        while (text.length > 0) {
            NSString *subString = [text substringToIndex:MIN(text.length, 4)];
            newString = [newString stringByAppendingString:subString];
            if (subString.length == 4) {
                newString = [newString stringByAppendingString:@" "];
            }
            text = [text substringFromIndex:MIN(text.length, 4)];
        }
        newString = [newString stringByTrimmingCharactersInSet:[characterSet invertedSet]];
        // 限制长度 银行卡号<＝32位
        if (newString.length >= 40) {
            return NO;
        }
        [banknumtf setText:newString];
        return NO;
        
    }
    
    return YES;
}
#pragma mark - - - - -- - - - 禁止可被复制粘贴 － － － － －－ － － －
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    return NO;
}


#pragma mark - - - - - - - - - - -  Action - - - - - - - - - - - - -
- (void)enterClick:(UIButton *)btn{
    
    switch (btn.tag) {
        case return_tag:
            //返回
            [self.navigationController popViewControllerAnimated:YES];
            break;
        case next_tag:
            //下一步
        {
            NSLog(@"下一步");
            
            float chongzhinum = [jinetf.text floatValue];
            if (chongzhinum > 10000.00 ) {
                ALERT(@"提示", @"充值金额不超过10000元", self, @"确定", nil);
                return;
            }

            //显示键盘
            if (banknumtf.text.length !=0 && usernametf.text.length !=0 && banknaemtf.text.length !=0) {

                [UIView animateWithDuration:0.5 animations:^{
                    [jinetf resignFirstResponder];
                    [self.view addSubview:mengbanview];
                    [self.view addSubview:zhifuview];
                    float fuwu = [jinetf.text floatValue]*0.001;
                    fuwulabel.text = [NSString stringWithFormat:@"提现金额%@.00元，服务费%.2f元",jinetf.text,fuwu];
                    NSLog(@"mengban y %f,zhifuview y %f",mengbanview.frame.origin.y,zhifuview.frame.origin.y);
                    [textFieldmima becomeFirstResponder];
                    textFieldmima.keyboardType = UIKeyboardTypeNumberPad;
                    [self  initPwdTextField]; //
                    
                }];
 
                
            }else{
                if (banknumtf.text.length <= 18) {
                    ALERT(@"提示", @"请将卡号填写完整", self, @"确定", nil);
                }
                else if (usernametf.text.length == 0){
                    ALERT(@"提示", @"请将账户姓名填写完整", self, @"确定", nil);

                }else if (banknaemtf.text.length == 0){
                
                    ALERT(@"提示", @"请将开户行填写完整", self, @"确定", nil);

                }
                
                return ;
            }
            
            break;
        }
        case tixian_tag:
        {
        //全部提现
            NSLog(@"全部体现");
            break;
        
        }
        case cancel_tag:
        {
            //隐藏支付view
            [mengbanview removeFromSuperview];
            [zhifuview removeFromSuperview];
            [self.view endEditing:YES];
            [self  clearUpPassword];//清除密码
            break;
        }
        case forget_tag:
        {
            //
            [mengbanview removeFromSuperview];
            [zhifuview removeFromSuperview];
            [self.view endEditing:YES];
            [self  clearUpPassword];//清除密码
            ZhifuPass1ViewController * zhifuchange = [[ZhifuPass1ViewController alloc]init];
            [self.navigationController pushViewController:zhifuchange animated:YES];
        }
        default:
            break;


    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [self.view endEditing:YES];
    return YES;
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self.view endEditing:YES];
}
- (AFHTTPSessionManager*)manger{
    
    if (!_manger) {
        
        _manger = [AFHTTPSessionManager manager];
        
        _manger.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        _manger.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json", nil];
    }
    
    return _manger;
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
